package android.tvtt.yd360;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.text.TextUtils;
//import android.support.v7.app.ActionBarActivity;
import android.tvtt.utils.DebugLog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.Toast;

public class StartPageActivity extends Activity {

	static Context context;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.trang_chu_layout);

		context = StartPageActivity.this;
		//getActionBar().setDisplayHomeAsUpEnabled(true);
		getActionBar().setHomeButtonEnabled(true);

		Fragment fragment = new PlaceholderFragment();
		FragmentManager fragmentManager = getFragmentManager();
		fragmentManager.beginTransaction().add(R.id.container, fragment)
				.commit();

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.action_menu, menu);

		// Associate searchable configuration with the SearchView
		//SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
		SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
				.getActionView();
		searchView.setQueryHint("Drug Search");

//		searchView.setSearchableInfo(searchManager
//				.getSearchableInfo(getComponentName()));
		searchView.setOnQueryTextListener(queryListener);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.

		int id = item.getItemId();
		switch (id) {
		case R.id.action_search:
			// search action
			return true;
		case android.R.id.home:
			return true;

		default:
			return super.onOptionsItemSelected(item);
		}
		// if (id == R.id.action_websearch) {
		// return true;
		// }
	}

	final private OnQueryTextListener queryListener = new OnQueryTextListener() {       

	    @Override
	    public boolean onQueryTextChange(String newText) {
//	        if (TextUtils.isEmpty(newText)) {
//	            getActionBar().setSubtitle("List");               
//	        }   
	        //Log.e("Test changed",newText);
	        return false;
	    }

	    @Override
	    public boolean onQueryTextSubmit(String query) {            
	        Toast.makeText(context, "Searching for: " + query + "...", Toast.LENGTH_SHORT).show();
	        return false;
	    }
	};

	/**
	 * A placeholder fragment containing a simple view.
	 */
	public static class PlaceholderFragment extends Fragment {

		Button btn1, btn2, btn3, btn4, btn5, btn6;

		public PlaceholderFragment() {
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_main, container,
					false);
			btn1 = (Button) rootView.findViewById(R.id.button1);
			btn2 = (Button) rootView.findViewById(R.id.button2);
			btn3 = (Button) rootView.findViewById(R.id.button3);
			btn4 = (Button) rootView.findViewById(R.id.button4);
			btn5 = (Button) rootView.findViewById(R.id.button5);
			btn6 = (Button) rootView.findViewById(R.id.button6);

			btn1.setOnClickListener(OnButtonClicked);
			btn2.setOnClickListener(OnButtonClicked);
			btn3.setOnClickListener(OnButtonClicked);
			btn4.setOnClickListener(OnButtonClicked);
			btn5.setOnClickListener(OnButtonClicked);
			btn6.setOnClickListener(OnButtonClicked);

			return rootView;
		}

		OnClickListener OnButtonClicked = new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switch (v.getId()) {
				case R.id.button1:
					DebugLog.d("YD360:------BUTTON 1 CLICKED---------");
					Intent intent = new Intent(context,
							TraCuuDuocActivity.class);
					intent.putExtra("vTitle", R.string.activity_module_title_1);
					intent.putExtra("vGroupID", 1);
					startActivity(intent);
					break;
				case R.id.button2:

					break;
				case R.id.button3:

					break;
				case R.id.button4:

					break;
				case R.id.button5:

					break;
				case R.id.button6:

					break;

				default:
					break;
				}
			}
		};

	}
}
